package com.ruoyi.sale.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.sale.domain.SysAccount;
import com.ruoyi.sale.service.ISysAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 账户管理Controller
 * 
 * @author ruoyi
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/account")
public class SysAccountController extends BaseController
{
    @Autowired
    private ISysAccountService sysAccountService;

    /**
     * 查询账户管理列表
     */
    @RequiresPermissions("system:account:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAccount sysAccount)
    {
        startPage();
        List<SysAccount> list = sysAccountService.selectSysAccountList(sysAccount);
        return getDataTable(list);
    }

    /**
     * 导出账户管理列表
     */
    @RequiresPermissions("system:account:export")
    @Log(title = "账户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAccount sysAccount)
    {
        List<SysAccount> list = sysAccountService.selectSysAccountList(sysAccount);
        ExcelUtil<SysAccount> util = new ExcelUtil<SysAccount>(SysAccount.class);
        util.exportExcel(response, list, "账户管理数据");
    }

    /**
     * 获取账户管理详细信息
     */
    @RequiresPermissions("system:account:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysAccountService.selectSysAccountById(id));
    }

    /**
     * 新增账户管理
     */
    @RequiresPermissions("system:account:add")
    @Log(title = "账户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAccount sysAccount)
    {
        return toAjax(sysAccountService.insertSysAccount(sysAccount));
    }

    /**
     * 修改账户管理
     */
    @RequiresPermissions("system:account:edit")
    @Log(title = "账户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAccount sysAccount)
    {
        return toAjax(sysAccountService.updateSysAccount(sysAccount));
    }

    /**
     * 删除账户管理
     */
    @RequiresPermissions("system:account:remove")
    @Log(title = "账户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAccountService.deleteSysAccountByIds(ids));
    }
}
